@extends('app')

@section('content')
<link href="{{ asset('/css/spinners.css') }}" rel="stylesheet">

<div id="grid" class="grid" style="position: fixed;z-index: 1000;left:50%;display: none;">
    <div class="cell">
        <div class="card">
            <span class="throbber-loader">Loading…</span>
        </div>
    </div>
</div>
<ul class="nav nav-tabs">
    <li class="active"><a href="{{url('/admin/teaches/index')}}">课程列表</a></li>
     <li><a href="{{url('admin/teaches/index/create')}}">新增课程</a></li>
</ul>
<div class="panel panel-default mt20">
    <div class="panel-heading">课程信息</div>
    <div class="table-responsive panel-body">
        <div class="col-xs-12 col-sm-3 col-md-4"><img src="@if(count($result->attachment)>0){{$result->attachment->url}}@endif" width="280"></div>
        <div class="col-sm-7 col-xs-12">
            <p>课程名称：{{ $result->name }} &nbsp;&nbsp;&nbsp; <span>价格:{{$result->price}}</span></p>
            <p>阅读须知：{{ $result->notice }}</p>
            <p>
                <span>学习人数：{{ $result->studys_num }}</span>&nbsp;&nbsp;&nbsp;
                <span>浏览数：{{ $result->views_num }}</span>&nbsp;&nbsp;&nbsp;
                <span>评论数：{{ $result->comments_num }}</span>&nbsp;&nbsp;&nbsp;
                <span>收藏数：{{ $result->attention_num }}</span>&nbsp;&nbsp;&nbsp;
           </p>
        </div>
    </div>
</div> 
<div class="panel panel-info mt20">
    <div class="panel-heading">新增</div>
    <div class="table-responsive panel-body">
        <div class="form-group">
            <form id="chapterForm">
                <div class="input-group">
                    <div class="input-group-addon">章节名称</div>
                    <input class="form-control" name="name" type="text" value="" placeholder="章节名称">
                    <div class="input-group-addon">章节价格</div>
                    <input class="form-control" name="price" type="text" value="0" placeholder="章节价格，为0免费">
                </div>
                <div class="form-group mt10">
                    <input type="hidden" name="user_id" value="{{Auth::user()->id}}">
                    {!! csrf_field() !!}
                    <input type="hidden" name="teachesid" value="{{$result->id}}">
                    <button type="button" class="btn btn-default" onclick="saveData('{{url('/admin/teaches/index/chapter/add')}}','chapterForm')">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="panel panel-default mt20">
    <div class="table-responsive panel-body">
        <table class="table table-hover">
          <thead>
            <tr>
              <th></th>
              <th>编号</th>
              <th>名称</th>
              <th>作者</th>
              <th width="10%">价格</th>
              <th>发布时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
          @foreach($result->chapters as $res)
            <form id="chapterForm_{{$res->id}}">
            <input type="hidden" name="chapterid" value="{{$res->id}}">
            {!! csrf_field() !!}
            <tr id="news_{{ $res->id }}">
              <td><a href="javascript:void(0)" onclick="saveData('{{url('/admin/teaches/index/chapter/add')}}','chapterForm_{{$res->id}}')"><font color="red"><i class="glyphicon glyphicon-ok"></i></font></a></td>
              <td>{{ $res->id }}</td>
              <td><input type="text" name="name" class="form-control" value="{{ $res->name }}"> </a></td>
              <td>{{ count($res->userinfo)>0?$res->userinfo->name:$result->user->name }}</td>
              <td><input type="text" name="price" class="form-control" value="{{ $res->price }}"></td>
              <td>{{ $res->created_at}}</td>
              <td>
                <a href="{{url('/admin/teaches/index/course/index/'.$res->id)}}">教程列表</a>&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="javascript:void(0);" onclick="delete_one('/admin/teaches/index/chapter/{{$res->id}}','{{$res->id}}','{{ csrf_token() }}')"><i class="glyphicon glyphicon-remove-sign"></i></a>
             </td>
            </tr>
            </form>
          @endforeach
          </tbody>
        </table>
    </div>
</div>

@endsection
